from apiflask import Schema
from apiflask.fields import String, Integer, Email
from marshmallow.validate import Length, Regexp


class UserLoginInSchema(Schema):
    username = String(required=True, validate=Length(5, 10))
    password = String(required=True, validate=Length(5, 20))

class BaseOutSchema(Schema):
    code = Integer()
    message = String()


class UserLoginOutSchema(BaseOutSchema):
    pass

class RegUserInSchema(Schema):
    username = String(required=True, validate=[
        Length(5, 15), 
        Regexp('^[a-zA-Z0-9]*$', error='he username should contain only a-z, A-Z and 0-9.')
    ])
    password = String(required=True, validate=Length(5, 20))
    phone = String(required=True)
    email = Email(required=True)
    sex = String(default="unknow")
    grad = Integer()
    personal_sign = String(default="每天写点小代码")


class RegUserOutSchema(Schema):
    username = String()
    email = Email()
    phone = String()
